package com.cloud.workTest;

import com.alibaba.fastjson.JSON;
import com.cloud.utils.HttpClientUtils;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PirQueryTest {

    static class Param {
        public String servingId;
        public List<String> queryValList;
    }
    public static void main(String[] args) throws Exception {

        Param param = new Param();

        param.servingId = "9e13d9b0bdc54aebb46ed3e42025c81d";
        List<String> queryValList = new ArrayList<>();
        param.queryValList = queryValList;

        FileReader file = new FileReader("f://beta_query_data_10000w.csv");
        BufferedReader buffer = new BufferedReader(file);
        buffer.readLine();
        String paramsLine = "";
        for (int i = 0; i < 100; ++i) {
            paramsLine = buffer.readLine();
            String[] tableParams = paramsLine.split(",");
            queryValList.add(tableParams[0]);
        }

        String url = "http://192.168.88.103:18080/pir/online/query";
        String json = JSON.toJSONString(param);
        System.out.println(json);
        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        HttpPost httpPost = new HttpPost(url);

        StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
        httpPost.setEntity(entity);
        try {
            response = httpClient.execute(httpPost);
            System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            response.close();
            httpClient.close();
        }
    }
}
